#include "stdafx.h"

#include "MainMenuScreen.h"

namespace ETM
{
	namespace GameScreens
	{
		MainMenuScreen::MainMenuScreen()
		{

		}

		void MainMenuScreen::Initialize()
		{
			
		}

		void MainMenuScreen::Load()
		{
			selectedEntry = 0;

			menuEntries.push_back(sf::String("New Game", *FM.GetResource("Fonts/Moire-Regular.ttf")));
			menuEntries.push_back(sf::String("Load Game", *FM.GetResource("Fonts/Moire-Regular.ttf")));
			menuEntries.push_back(sf::String("Options", *FM.GetResource("Fonts/Moire-Regular.ttf")));
			menuEntries.push_back(sf::String("Quit", *FM.GetResource("Fonts/Moire-Regular.ttf")));

			music.OpenFromFile("Music/Private Reflection.ogg");
			title = sf::Sprite(*IM.GetResource("Images/title.png"));
			background = sf::Sprite(*IM.GetResource("Images/background.jpg"));

			music.Play();
		}

		void MainMenuScreen::Update(float delta)
		{
			if(Input::IsMenuUp())
				selectedEntry--;
			else if(Input::IsMenuDown())
				selectedEntry++;
			else if(Input::IsMenuSelect())
			{
				switch(selectedEntry)
				{
				case 0:
					music.Stop();
					screenManager->AddScreen(new GamePlayScreen());
					break;
				case 1:

					break;
				case 2:

					break;
				case 3:
					screenManager->Exit();
					break;
				}
			}

			if(selectedEntry < 0)
				selectedEntry = menuEntries.size() - 1;
			else if(selectedEntry > (int)menuEntries.size() - 1)
				selectedEntry = 0;

			for(unsigned int i = 0; i < menuEntries.size(); i++)
			{
				if(i == selectedEntry)
					menuEntries[i].SetColor(sf::Color(255, 255, 255));
				else
					menuEntries[i].SetColor(sf::Color(125, 125, 125));
			}
		}

		void MainMenuScreen::Render(sf::RenderWindow& window)
		{
			window.SetView(window.GetDefaultView());

			window.Draw(background);
			window.Draw(title);

			for(unsigned int i = 0; i < menuEntries.size(); i++)
			{
				float x = 330;
				float y = 250;
				menuEntries[i].SetPosition(x, y + i * 64);
				Utils::RenderShadowText(window, menuEntries[i]);
			}
		}
	}
}